package com.biao.hashmap;

public class Demo04_Array_HashMap<K, V> {
    private Entry[] entrys = new Entry[1000];

    class Entry<K, V> {
        K k;
        V v;

        public Entry(K k, V v) {
            this.k = k;
            this.v = v;
        }
    }

    public void put(K k, V v) {
        int index = k.hashCode() % entrys.length;
        entrys[index] = new Entry<K, V>(k, v);
    }

    public V get(K k) {
        int index = k.hashCode() % entrys.length;
        return (V) entrys[index].v;
    }

    public static void main(String[] args) {
        Demo04_Array_HashMap<Object, String> map = new Demo04_Array_HashMap<>();
        map.put("a", "a");
        map.put(97, "97");
        System.out.println(map.get("a"));   // 97

        // 发生了hash冲突，所以产生被覆盖的现象
    }
}
